//
//  AL_ViewController_SingDetail.m
//  22-homework-QQMV-ALi
//
//  Created by 王道林 on 16/8/15.
//  Copyright © 2016年 王道林. All rights reserved.
//
#define COLORAUTO [UIColor colorWithRed:(arc4random()%256/255.0) green:(arc4random()%256/255.0) blue:(arc4random()%256/255.0) alpha:1.0]

#import "AL_ViewController_SingDetail.h"
#import "WHSNetworkParser.h"
#import "UIImageView+WebCache.h"
#import "AL_ModelSingDetail.h"
@interface AL_ViewController_SingDetail ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) AL_ModelSingDetail *modelSingDetail;
@end

@implementation AL_ViewController_SingDetail

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = COLORAUTO;
    // Do any additional setup after loading the view.
    [self createData];
    [self createSubView];
}

// 数据出来后才能设置的空间及属性
- (void)setAttribute
{
    // 设置navigation
    self.navigationItem.title = _modelSingDetail.name;
   
    UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 250)];
    [iamgeView sd_setImageWithURL:[NSURL URLWithString:_modelSingDetail.picUrl] placeholderImage:[UIImage imageNamed:@"1"]];
    _tableView.tableHeaderView = iamgeView;
    
    
}



- (void)createData
{
    NSString *path = [NSString stringWithFormat:@"http://api.dongting.com/song/album/%@", _value];
    NSLog(@"%@", path);
    [WHSNetworkParser GETWithURL:path par:nil success:^(id responseObject) {
        _modelSingDetail = [AL_ModelSingDetail modelWithDic:responseObject[@"data"]];        
//        NSLog(@"%@", _modelSingDetail.songList);
        [self setAttribute];
        [_tableView reloadData];
    } filed:^(NSError *error) {
        
    }];
}

- (void)createSubView
{
    // 设置navigation
    self.navigationItem.title = _modelSingDetail.name;
    
    _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"pool"];
}


// 代理返回分区个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

// 返回每个分区cell的个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 0;
    } else if (section == 1)
    {
        return _modelSingDetail.songList.count;
    }
    return 0;
}



// 返回cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool" forIndexPath:indexPath];
    cell.backgroundColor = COLORAUTO;
    return cell;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
